from django.db import models
from apps.goods.models import Goods
from apps.user.models import User

class Cart(models.Model):
    cart_id = models.AutoField(primary_key=True, unique=True, verbose_name="购物车ID")
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
    total_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="购物车总价")
    total_goods_number = models.IntegerField(null=False, default=0, verbose_name="全部商品数")

    # def __str__(self):
    #     return f'{self.user.name} - {self.total_price}'

    class Meta:
        db_table = 'cart'

class CartItem(models.Model):
    cart_item_id = models.AutoField(primary_key=True, unique=True, verbose_name="购物车项ID")
    cart = models.ForeignKey(Cart, on_delete=models.CASCADE, related_name='item', verbose_name="购物车")
    good = models.ForeignKey(Goods, on_delete=models.CASCADE, verbose_name='商品')
    num = models.IntegerField(default=0, verbose_name='购买数量')
    is_delete = models.BooleanField(default=0, choices=[(0, '未被清空'), (1, '已被清空')], verbose_name='是否删除')

    # def __str__(self):
    #     return f'{self.good.name} - {self.num}'

    class Meta:
        db_table = 'cart_item'